package com.universest.swordholder.task

import kotlinx.coroutines.flow.Flow

class ConvertTask<A,B,C>(val task: AbstractTask<A,B>,name: String = task.name,val converter: (B) -> C) : AbstractTask<A,C>(name) {
    override suspend fun call(param: A): C {
        return converter(task.execute(param).getOrThrow())
    }

    override val progress: Flow<Pair<Int, Int>>
        get() = task.progress
    override val message: Flow<String>
        get() = task.message

    override suspend fun cancel() {
        super.cancel()
        task.cancel()
    }
}